<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/24
 * Time: 17:32
 */

namespace app\lib\Validate;

use app\lib\Exception\ValidateException;
use think\Request;
use think\Validate;
 
class BaseValidate extends Validate
{
    public function goCheck()
    {
        $request = Request::instance();
        $params = $request->param();
        //我cao原来罪魁祸首是你↓
        //dump($params);
        if(!$this->check($params))
        {
            $exception = new ValidateException([
                'message' => is_array($this->error) ? implode(
                    ';', $this->error) : $this->error,
                'code' => 500,
                'error_code' => 10001
            ]);

            throw $exception;
        }
        return true;
    }

    protected function isIntegerNumber($value,$rule = '',$data = '',$field = '')
    {
        if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) {
            return true;
        }
        return false;
    }

    protected function isNotEmpty($value,$rule = '',$data = '',$field = '')
    {
        if(empty($value))
        {
            return $field . '不能为空';
        }else{
            return true;
        }
    }

    public function getByDateRule($param)
    {
        if(array_key_exists('user_id',$param) || array_key_exists('uid',$param))
        {
            throw new ValidateException([
                'message' => '提交的参数中含有uid或者user_id',
                'code' => 499
            ]);
        }
        $array = [];
        foreach($param as $key=>$value) {
            $array[$key] = $param[$key];
        }

        return $array;
    }
}